package com.soonoh.simplecube.cube;

public class Cube {

	public static final int FRONT = 0;
	public static final int LEFT = 1;
	public static final int BACK = 2;
	public static final int RIGHT = 3;
	public static final int TOP = 4;
	public static final int BOTTOM = 5;
	public static final int HIDDEN = 7;

	private int[] X_ROTATE_FACES = { FRONT, TOP, BACK, BOTTOM };
	private int[] Y_ROTATE_FACES = { FRONT, LEFT, BACK, RIGHT };
	private int[] Z_ROTATE_FACES = { TOP, RIGHT, BOTTOM, LEFT };
	private int[][] AXIS_ROTATE_FACES = {
			X_ROTATE_FACES, Y_ROTATE_FACES, Z_ROTATE_FACES
	};
	
	public static final int CUBE_FACE_SIZE = 6;
	
	int[] colours = new int[CUBE_FACE_SIZE];
	
	public Cube() {
		init();
	}

    void init() {
        for(int i = 0; i < CUBE_FACE_SIZE; ++i ) {
            colours[i] = HIDDEN;
        }
    }

	public void rotate(int[] rotatedFaces, int axes, int direction) {
        int i;
		//int rotatedFaces[] = new int[CUBE_FACE_SIZE];
        for( i = 0; i < CUBE_FACE_SIZE; ++i ) {
            rotatedFaces[i] = this.colours[i];
        }
		int step = 0;
		int[] orders = null;
		orders = AXIS_ROTATE_FACES[axes];
		step = direction;
		for ( i = 0; i < orders.length; ++i ) {
			int ii = i+step;
			if (ii >= orders.length) {
				ii -= orders.length;
			}
			if (ii < 0) {
				ii += orders.length;
			}
			rotatedFaces[orders[i]] = this.colours[orders[ii]];
		}
	}
	public void setColours(int[] colours) {
		for (int i = 0; i < CUBE_FACE_SIZE; ++i) {
			this.colours[i] = colours[i];
		}
	}
	public void setColour(int face, int colour) {
		this.colours[face] = colour;
	}
	public int getColour(int face) {
		return this.colours[face];
	}
	public int[] getColours() {
		return this.colours;
	}
}

